package com.timous.数组;
/**
 * https://leetcode-cn.com/problems/how-many-numbers-are-smaller-than-the-current-number/
 */
public class _1365_有多少小于当前数字的数字 {
    public int[] smallerNumbersThanCurrent(int[] nums) {

        int[] array = new int[nums.length];
        for (int i = 0; i < nums.length; i++) {
            int count = 0;
            for (int j = 0; j < nums.length; j++) {
                if(nums[i] > nums[j]){
                    count++;
                }
            }
            array[i] = count;
        }
        return array;

    }

    public int[] smallerNumbersThanCurrent2(int[] nums) {

        int[] array = new int[101];
        for (int i = 0; i <= 100; i++) {
            array[i] = 0;
        }
        for (int i = 0; i < nums.length; i++) {
            array[nums[i]]++;
        }
        for (int i = 0; i < nums.length; i++) {
            int count = 0;
            for (int j = 0; j < nums[i]; j++) {
                count += array[j];
            }
            nums[i] = count;
        }
        return nums;
    }
}
